﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Popups;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
// The User Control item template is documented at http://go.microsoft.com/fwlink/?LinkId=234236
using Waiter.ServiceReference1;

namespace Waiter
{
    public sealed partial class ListMonAn : UserControl
    {
        public event EventHandler ClosePopup;
        public ListMonAn(Category cg)
        {
            this.InitializeComponent();
            init(cg);
        }

        public async void init(Category cg)
        {
            Service1Client client = new Service1Client();
            List<Item> itemsInCategory = await client.GetItemsByCategoryAsync(cg);
            itemsInCategoryListBox.ItemsSource = itemsInCategory;

        }
        private async void itemsInCategoryListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            Item item = (Item)(sender as ListBox).SelectedItem;
            if (item != null)
            {
                string itemStr = "" + item.Id + " " + item.Name;
                Debug.WriteLine(itemStr);
                Service1Client client = new Service1Client();
                await client.GoiMonAsync(GiaoDienChonMon.table, item, 1);  // Tạm thời để số lượng gọi là 1 vì chưa có giao diện nhập số lượng
                MessageDialog dl = new MessageDialog("Đã gửi yêu cầu món " + item.Name + " vào bếp.");
                dl.ShowAsync();
            }
        }
    }
}
